import { param2Obj } from '@/utils/myUtils'
import Mock from 'mockjs'
let Allarr=[]
for(var i=0;i<=100;i++){
    Allarr.push({
          id:Mock.mock('@id()'),
          date: Mock.mock('@csentence(5)'),
          nime:Mock.mock('@datetime()'),
          name: Mock.mock('@cname()'),
          avatar: Mock.Random.image('100x100', '#4A7BF7', 'Hello')
    })
}
export default {
    cmhData:(config)=>{
        // console.log(config);
        const{page,pageSize}=JSON.parse(config.body) 
        // console.log(page,pageSize);
        let newArr=[]
        newArr=Allarr.filter((item,index)=>{
            return (page-1) * pageSize <= index && index < page * pageSize
        })
        return{
            code:200,
            msg:'成功',
            data:newArr,
            total:Allarr.length
        }
    },
    delData:config=>{
        const { id } = JSON.parse(config.body)
        console.log(id);
        Allarr.forEach((item, index) => {
            if (item.id == id) {
                Allarr.splice(index, 1)
            }
        })
        return{
            code:201,
            msg:'删除成功',
            data:null
        }
    },
    tjaddData:(config)=>{
       let {name,username}= JSON.parse(config.body)
    //    let res= JSON.parse(config.body)
    //    console.log(res);
            Allarr.unshift({
                id:Mock.mock('@id()'),
                date:name,
                name:username,
                avatar: Mock.Random.image('100x100', '#4A7BF7', 'Hello'),
                nime:Mock.mock('@datetime()'),
            })
        return{
            code:202,
            msg:'添加成功',
            data:null
        }
    },
    //修改
    updataData:(config)=>{
            console.log(JSON.parse(config.body));
        return{
            code:203,
            msg:'修改成功',
            data:{
                id:Mock.mock('@id()'),
                date: Mock.mock('@csentence(5)'),
                nime:Mock.mock('@datetime()'),
                name: Mock.mock('@cname()'),
                avatar: Mock.Random.image('100x100', '#4A7BF7', 'Hello')
          }
        }
    }
}